package xFGE.util
{
	public class RandomUtil
	{
		public function RandomUtil()
			{
			super();
		}

        public static function randomElement(array:Array):*
        {
        	if(array == null) return null;
        	
        	var len:int = array.length;
        	if(len==0) return null;
        	
        	var ran:Number = Math.random();
            var a:int = len/10;
            if(a<1) a = 1;
            var index:int = int(ran*1000*a  % len);
        	return array[index];
        }

        public static function random(n:int):int
        {	
        	if(n<1) return 0;
        	
        	var ran:Number = Math.random();
            var a:int = (n+1)/10;
            if(a<1) a = 1;
            var result:int = int(ran*1000*a  % (n+1));
        	return result;
        }
        
        public static function randomScope(min:int,max:int):int
        {	
        	if(min<0 || max<0 || min>=max) return -1;
        	
        	var ran:Number = random(max);
        	while(ran<min){
        		ran= random(max);
        	}
        	return ran;
        }
        
	}
}